package com.example.basic.web.controller.shiftRecord;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.pharm.Pharm;
import com.example.basic.web.model.pharmZone.PharmZone;
import com.example.basic.web.model.shiftRecord.ShiftRecord;
import com.example.basic.web.response.OutNoticeResponse;
import com.example.basic.web.response.ShiftRecordResponse;
import com.example.basic.web.service.shiftRecord.ShiftRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Api(value  = "移位单", tags = {"移位单"})
@RestController
@RequestMapping("/api/v1/byg/shiftRecord")
public class ShiftRecordController {

    @Resource
    private ShiftRecordService shiftRecordService;

    @Log(title = "移位单", description = "新增")
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/add")
    public Result<ShiftRecord> add(@ApiParam(name = "shiftRecord", value = "模型", required = true) @RequestBody ShiftRecord shiftRecord) {
        return ResultGenerator.genSuccessResult(shiftRecordService.add(shiftRecord));
    }

    @Log(title = "移位单", description = "审核")
    @ApiOperation(value = "审核", notes = "审核")
    @PostMapping("/audit")
    public Result<Boolean> audit(@ApiParam(name = "shiftCode", value = "移位单编码") @RequestParam String shiftCode) {
        return ResultGenerator.genSuccessResult(shiftRecordService.audit(shiftCode));
    }

    @Log(title = "移位单", description = "取消移位")
    @ApiOperation(value = "取消移位", notes = "取消移位")
    @PostMapping("/cancel")
    public Result<Boolean> cancel(@ApiParam(name = "shiftCode", value = "移位单编码") @RequestParam String shiftCode) {
        return ResultGenerator.genSuccessResult(shiftRecordService.cancel(shiftCode));
    }

    @Log(title = "移位单", description = "列表")
    @ApiOperation(value = "列表", notes = "列表")
    @PostMapping("/queryList")
    public Result<IPage<ShiftRecordResponse>> queryList(
            @ApiParam(name = "searchParam", value = "模糊搜索(遗体名称，拼音码，五笔码)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "sex", value = "性别 0-全部") @RequestParam(defaultValue = "0") String sex,
            @ApiParam(name = "type", value = "1-所入，2-移入") @RequestParam(defaultValue = "0") String type,
            @ApiParam(name = "pharmCode", value = "库房编码 0-全部") @RequestParam(defaultValue = "0") String pharmCode,
            @ApiParam(name = "zoneCode", value = "分区编码 0-全部") @RequestParam(defaultValue = "0") String zoneCode,
            @ApiParam(name = "depotCode", value = "库位编码 0-全部") @RequestParam(defaultValue = "0") String depotCode,
            @ApiParam(name = "beginTime", value = "开始日期") @RequestParam(required = false) String beginTime,
            @ApiParam(name = "endTime", value = "结束日期") @RequestParam(required = false) String endTime,
            @ApiParam(name = "page", value = "页数，list分页的第几页") @RequestParam(defaultValue = "0") Integer page,
            @ApiParam(name = "size", value = "条数，list分页的每页条数") @RequestParam(defaultValue = "0") Integer size) {
        Page<ShiftRecordResponse> queryPage = new Page<>(page,size);
        return ResultGenerator.genSuccessResult(shiftRecordService.queryList(queryPage,searchParam,sex,type,pharmCode,zoneCode,depotCode,beginTime,endTime));
    }
}
